All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.swing.tree.DefaultTreeSelectionModel

java.lang.Object
   |
   +----com.sun.java.swing.tree.DefaultTreeSelectionModel

public class DefaultTreeSelectionModel
extends Object
implements Cloneable, Serializable, TreeSelectionModel
Implementation of TreeSelectionModel. Listeners are notified whenever the paths in the selection change, not the rows. In order to be able to track row changes you may wish to become a listener for expansion events on the tree and test for changes from there.

Warning: serialized objects of this class will not be compatible with future swing releases. The current serialization support is appropriate for short term storage or RMI between Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.


Variable Index

 o changeSupport
Used to messaged registered listeners.
 o leadIndex
Index of the lead path in selection.
 o leadPath
Last path that was added.
 o leadRow
Lead row.
 o listenerList
Event listener list.
 o listSelectionModel
Handles maintaining the list selection model.
 o rowMapper
Provides a row for a given path.
 o selection
Paths that are currently selected.
 o SELECTION_MODE_PROPERTY
Property name for selectionMode.
 o selectionMode
Mode for the selection, will be either SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.

Constructor Index

 o DefaultTreeSelectionModel()

Method Index

 o addPropertyChangeListener(PropertyChangeListener)
Add a PropertyChangeListener to the listener list.
 o addSelectionPath(TreePath)
Adds path to the current selection.
 o addSelectionPaths(TreePath[])
Adds paths to the current selection.
 o addTreeSelectionListener(TreeSelectionListener)
Adds x to the list of listeners that are notified each time the selection changes.
 o arePathsContiguous(TreePath[])
Returns true if the paths are contiguous.
 o canPathsBeAdded(TreePath[])
Returns true if the paths can be added without breaking the continuity of the model.
 o canPathsBeRemoved(TreePath[])
Returns true if the paths can be removed without breaking the continuity of the model.
 o clearSelection()
Empties the current selection.
 o clone()
Returns a clone of the reciever with the same selection.
 o fireValueChanged(TreeSelectionEvent)
 o getLeadSelectionPath()
Returns the last path that was added.
 o getLeadSelectionRow()
Returns the lead selection index.
 o getMaxSelectionRow()
Gets the last selected row.
 o getMinSelectionRow()
Gets the first selected row.
 o getRowMapper()
Returns the RowMapper instance that is able to map a path to a row.
 o getSelectionCount()
Returns the number of paths that are selected.
 o getSelectionMode()
Returns the selection mode.
 o getSelectionPath()
Returns the first path in the selection.
 o getSelectionPaths()
Returns the paths in the selection.
 o getSelectionRows()
Returns all of the currently selected rows.
 o insureRowContinuity()
Useful for CONTIGUOUS_TREE_SELECTION.
 o insureUniqueness()
Insures that all the elements in path are unique.
 o isPathSelected(TreePath)
Returns true if the path, path, is in the current selection.
 o isRowSelected(int)
Returns true if the row identitifed by row is selected.
 o isSelectionEmpty()
Returns true if the selection is currently empty.
 o notifyPathChange(Vector, TreePath)
Notifies listeners of a change in path.
 o removePropertyChangeListener(PropertyChangeListener)
Remove a PropertyChangeListener from the listener list.
 o removeSelectionPath(TreePath)
Removes path from the selection.
 o removeSelectionPaths(TreePath[])
Removes paths from the selection.
 o removeTreeSelectionListener(TreeSelectionListener)
Removes x from the list of listeners that are notified each time the selection changes.
 o resetRowSelection()
Recalculates what rows are selected by asking the RowMapper for the row for each path.
 o setRowMapper(RowMapper)
Sets the RowMapper instance.
 o setSelectionMode(int)
Sets the selection model, which must be one of SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
 o setSelectionPath(TreePath)
Sets the selection to path.
 o setSelectionPaths(TreePath[])
Sets the selection to the paths in paths.
 o toString()
 o updateLeadIndex()
Updates the leadIndex instance variable.

Variables

 o SELECTION_MODE_PROPERTY
 public static final String SELECTION_MODE_PROPERTY
Property name for selectionMode.

 o changeSupport
 protected PropertyChangeSupport changeSupport
Used to messaged registered listeners.

 o selection
 protected TreePath selection[]
Paths that are currently selected. Will be null if nothing is currently selected.

 o listenerList
 protected EventListenerList listenerList
Event listener list.

 o rowMapper
 protected transient RowMapper rowMapper
Provides a row for a given path.

 o listSelectionModel
 protected DefaultListSelectionModel listSelectionModel
Handles maintaining the list selection model.

 o selectionMode
 protected int selectionMode
Mode for the selection, will be either SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.

 o leadPath
 protected TreePath leadPath
Last path that was added.

 o leadIndex
 protected int leadIndex
Index of the lead path in selection.

 o leadRow
 protected int leadRow
Lead row.

Constructors

 o DefaultTreeSelectionModel
 public DefaultTreeSelectionModel()

Methods

 o setRowMapper
 public void setRowMapper(RowMapper newMapper)
Sets the RowMapper instance. This instance is used to determine what row corresponds to what path.

 o getRowMapper
 public RowMapper getRowMapper()
Returns the RowMapper instance that is able to map a path to a row.

 o setSelectionMode
 public void setSelectionMode(int mode)
Sets the selection model, which must be one of SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.

 o getSelectionMode
 public int getSelectionMode()
Returns the selection mode.

 o setSelectionPath
 public void setSelectionPath(TreePath path)
Sets the selection to path. If this represents a change, then the TreeSelectionListeners are notified.

Parameters:
path - new path to select
 o setSelectionPaths
 public void setSelectionPaths(TreePath pPaths[])
Sets the selection to the paths in paths. If this represents a change the TreeSelectionListeners are notified. Potentially paths will be held by the reciever, in other words don't change any of the objects in the array once passed in.

Parameters:
paths - new selection.
 o addSelectionPath
 public void addSelectionPath(TreePath path)
Adds path to the current selection. If path is not currently in the selection the TreeSelectionListeners are notified.

Parameters:
path - the new path to add to the current selection.
 o addSelectionPaths
 public void addSelectionPaths(TreePath paths[])
Adds paths to the current selection. If any of the paths in paths are not currently in the selection the TreeSelectionListeners are notified.

Parameters:
path - the new path to add to the current selection.
 o removeSelectionPath
 public void removeSelectionPath(TreePath path)
Removes path from the selection. If path is in the selection The TreeSelectionListeners are notified.

Parameters:
path - the path to remove from the selection.
 o removeSelectionPaths
 public void removeSelectionPaths(TreePath paths[])
Removes paths from the selection. If any of the paths in paths are in the selection the TreeSelectionListeners are notified.

Parameters:
path - the path to remove from the selection.
 o getSelectionPath
 public TreePath getSelectionPath()
Returns the first path in the selection.

 o getSelectionPaths
 public TreePath[] getSelectionPaths()
Returns the paths in the selection.

 o getSelectionCount
 public int getSelectionCount()
Returns the number of paths that are selected.

 o isPathSelected
 public boolean isPathSelected(TreePath path)
Returns true if the path, path, is in the current selection.

 o isSelectionEmpty
 public boolean isSelectionEmpty()
Returns true if the selection is currently empty.

 o clearSelection
 public void clearSelection()
Empties the current selection. If this represents a change in the current selection, the selection listeners are notified.

 o addTreeSelectionListener
 public void addTreeSelectionListener(TreeSelectionListener x)
Adds x to the list of listeners that are notified each time the selection changes.

Parameters:
x - the new listener to be added.
 o removeTreeSelectionListener
 public void removeTreeSelectionListener(TreeSelectionListener x)
Removes x from the list of listeners that are notified each time the selection changes.

Parameters:
x - the listener to remove.
 o fireValueChanged
 protected void fireValueChanged(TreeSelectionEvent e)
 o getSelectionRows
 public int[] getSelectionRows()
Returns all of the currently selected rows.

 o getMinSelectionRow
 public int getMinSelectionRow()
Gets the first selected row.

 o getMaxSelectionRow
 public int getMaxSelectionRow()
Gets the last selected row.

 o isRowSelected
 public boolean isRowSelected(int row)
Returns true if the row identitifed by row is selected.

 o resetRowSelection
 public void resetRowSelection()
Recalculates what rows are selected by asking the RowMapper for the row for each path.

 o getLeadSelectionRow
 public int getLeadSelectionRow()
Returns the lead selection index. That is the last index that was added.

 o getLeadSelectionPath
 public TreePath getLeadSelectionPath()
Returns the last path that was added.

 o addPropertyChangeListener
 public synchronized void addPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list. The listener is registered for all properties.

A PropertyChangeEvent will get fired in response to an explicit setFont, setBackground, or SetForeground on the current component. Note that if the current component is inheriting its foreground, background, or font from its container, then no event will be fired in response to a change in the inherited property.

Parameters:
listener - The PropertyChangeListener to be added
 o removePropertyChangeListener
 public synchronized void removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.

Parameters:
listener - The PropertyChangeListener to be removed
 o insureRowContinuity
 protected void insureRowContinuity()
Useful for CONTIGUOUS_TREE_SELECTION. If the rows that are selected are not contiguous then the selection is reset to be contiguous. Or if the selection mode is single selection and more than one this is selected the selection is reset.

 o arePathsContiguous
 protected boolean arePathsContiguous(TreePath paths[])
Returns true if the paths are contiguous.

 o canPathsBeAdded
 protected boolean canPathsBeAdded(TreePath paths[])
Returns true if the paths can be added without breaking the continuity of the model.

 o canPathsBeRemoved
 protected boolean canPathsBeRemoved(TreePath paths[])
Returns true if the paths can be removed without breaking the continuity of the model. This is rather expensive.

 o notifyPathChange
 protected void notifyPathChange(Vector changedPaths,
                                 TreePath oldLeadSelection)
Notifies listeners of a change in path. changePaths should contain instances of PathPlaceHolder.

 o updateLeadIndex
 protected void updateLeadIndex()
Updates the leadIndex instance variable.

 o insureUniqueness
 protected void insureUniqueness()
Insures that all the elements in path are unique. This does not check for a null selection!

 o toString
 public String toString()
Overrides:
toString in class Object
 o clone
 public Object clone() throws CloneNotSupportedException
Returns a clone of the reciever with the same selection. selectionListeners, and PropertyListeners are not duplicated.

Throws: CloneNotSupportedException
if the receiver does not both (a) implement the Cloneable interface and (b) define a clone method.
Overrides:
clone in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index